16 January 2023

REPLICATION FILES FOR:  
	
	Assessing the Structure of Policy Preferences
	Christopher Hare, Ben Highton, and Bradford Jones
	Forthcoming in The Journal of Politics



INSTALL PACKAGES
================

For exact reproducibility, use R version 4.2.2.

Install the following packages from CRAN:

	install.packages(c("haven","MASS","pscl","MCMCpack","jtools",
	"huxtable","ggplot2","ggrepel","psych","Hmisc","reshape2",
	"cluster","smacof","gbm","dplyr","car","RColorBrewer","statar",
	"mokken","gridBase","gridExtra","mmpf","viridis","Matrix",
	"pROC","foreach","doParallel","kohonen","matlib","dmbc",
	"tidytext","ggmosaic","ggridges","ggalluvial","ggpubr",
	"rcartocolor","rasterpdf"), dependencies=TRUE)



INSTRUCTIONS
============

To replicate the paper's results, run the script "main.R". This file calls the following eight modules, with approximate run time (based on eight-core processing using Intel Core i7-8700K CPU @ 3.70GHz, 16GB RAM) in brackets:

"./0_definefunctions.R" [< 1 minute]
"./1_datapreprocessing.R" [< 1 minute]
"./2_fitstatistics.R" [10 hours]
"./3_stresssimulations.R" [94 hours]
"./4_mdsplots.R" [13 hours]
"./5_mdsexperiments.R" [10.5 hours]
"./6_sheparddiagrams.R" [17 minutes]
"./7_individualstress.R" [17.5 hours]

Note: if memory problems arise, can close R between modules. They are designed to run independently (though sequentially).

The "Routput.txt" file includes complete output from a test run of "main.R". 



CORRESPONDENCE
==============

The figure file names correspond to those in the manuscript and appendix (e.g., "figure_1.pdf").

The tables can be replicated using the following objects/commands:

Table A.1:
	(".4/mdsplots.R", line 1916)
	> export_summs(ols.left.categorical, ols.right.categorical, ols.extremeleft.categorical, 
		ols.extremeright.categorical, digits=3, statistics=c(N="nobs", R2="r.squared", 
		adj.R2="adj.r.squared", resid.sd="sigma"))

Table A.2:
	("./7_individualstress.R", line 694)
	> print(data.frame(Category = c("High (H3)", "Medium (M3)", "Low (L3)"),
  		N = c(sum(H3), sum(M3), sum(L3)),
  		Percentage = 100*c(sum(H3)/stressgroup.total, sum(M3)/stressgroup.total, 
		sum(L3)/stressgroup.total),
  		Correct.PartyPlacement = 100*c((sum(anes2012.correct.libcon.parties[H3])/sum(H3)), 
		(sum(anes2012.correct.libcon.parties[M3])/sum(M3)), 
		(sum(anes2012.correct.libcon.parties[L3])/sum(L3)))))
 	
Table A.3:
	("./7_individualstress.R", line 1179)
	> print(paste("H3, three dimensions (combined model) AUC:", 
		round(suppressMessages(roc(H3.anes2012.presvote.original3$y ~ 
		predict(H3.anes2012.presvote.original3, type=c("response")))$auc),3)))
		print(paste("H3, three dimensions (specific model) AUC:", 
		round(suppressMessages(roc(H3.anes2012.presvote.specific3$y ~ 
		predict(H3.anes2012.presvote.specific3, type=c("response")))$auc),3)))
		print(paste("H3, four dimensions (combined model) AUC:", 
		round(suppressMessages(roc(H3.anes2012.presvote.original4$y ~ 
		predict(H3.anes2012.presvote.original4, type=c("response")))$auc),3)))
		print(paste("H3, four dimensions (specific model) AUC:", 
		round(suppressMessages(roc(H3.anes2012.presvote.specific4$y ~ 
		predict(H3.anes2012.presvote.specific4, type=c("response")))$auc),3)))
		print(paste("H3, five dimensions (combined model) AUC:", 
		round(suppressMessages(roc(H3.anes2012.presvote.original5$y ~ 
		predict(H3.anes2012.presvote.original5, type=c("response")))$auc),3)))
		print(paste("H3, five dimensions (specific model) AUC:", 
		round(suppressMessages(roc(H3.anes2012.presvote.specific5$y ~ 
		predict(H3.anes2012.presvote.specific5, type=c("response")))$auc),3)))
		#
		print(paste("M3, three dimensions (combined model) AUC:", 
		round(suppressMessages(roc(M3.anes2012.presvote.original3$y ~ 
		predict(M3.anes2012.presvote.original3, type=c("response")))$auc),3)))
		print(paste("M3, three dimensions (specific model) AUC:", 
		round(suppressMessages(roc(M3.anes2012.presvote.specific3$y ~ 
		predict(M3.anes2012.presvote.specific3, type=c("response")))$auc),3)))
		print(paste("M3, four dimensions (combined model) AUC:", 
		round(suppressMessages(roc(M3.anes2012.presvote.original4$y ~ 
		predict(M3.anes2012.presvote.original4, type=c("response")))$auc),3)))
		print(paste("M3, four dimensions (specific model) AUC:", 
		round(suppressMessages(roc(M3.anes2012.presvote.specific4$y ~ 
		predict(M3.anes2012.presvote.specific4, type=c("response")))$auc),3)))
		print(paste("M3, five dimensions (combined model) AUC:", 
		round(suppressMessages(roc(M3.anes2012.presvote.original5$y ~ 
		predict(M3.anes2012.presvote.original5, type=c("response")))$auc),3)))
		print(paste("M3, five dimensions (specific model) AUC:", 
		round(suppressMessages(roc(M3.anes2012.presvote.specific5$y ~ 
		predict(M3.anes2012.presvote.specific5, type=c("response")))$auc),3)))
		#
		print(paste("L3, three dimensions (combined model) AUC:", 
		round(suppressMessages(roc(L3.anes2012.presvote.original3$y ~ 
		predict(L3.anes2012.presvote.original3, type=c("response")))$auc),3)))
		print(paste("L3, three dimensions (specific model) AUC:", 
		round(suppressMessages(roc(L3.anes2012.presvote.specific3$y ~ 
		predict(L3.anes2012.presvote.specific3, type=c("response")))$auc),3)))
		print(paste("L3, four dimensions (combined model) AUC:", 
		round(suppressMessages(roc(L3.anes2012.presvote.original4$y ~ 
		predict(L3.anes2012.presvote.original4, type=c("response")))$auc),3)))
		print(paste("L3, four dimensions (specific model) AUC:", 
		round(suppressMessages(roc(L3.anes2012.presvote.specific4$y ~ 
		predict(L3.anes2012.presvote.specific4, type=c("response")))$auc),3)))
		print(paste("L3, five dimensions (combined model) AUC:", 
		round(suppressMessages(roc(L3.anes2012.presvote.original5$y ~ 
		predict(L3.anes2012.presvote.original5, type=c("response")))$auc),3)))
		print(paste("L3, five dimensions (specific model) AUC:", 
		round(suppressMessages(roc(L3.anes2012.presvote.specific5$y ~ 
		predict(L3.anes2012.presvote.specific5, type=c("response")))$auc),3)))



SESSION INFO
============

R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server x64 (build 17763)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] parallel  stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] rcartocolor_2.0.0    ggpubr_0.5.0         ggalluvial_0.12.3   
 [4] ggridges_0.5.4       ggmosaic_0.3.3       tidytext_0.4.0      
 [7] dmbc_1.0.1           matlib_0.9.6         kohonen_3.0.11      
[10] doParallel_1.0.17    iterators_1.0.14     foreach_1.5.2       
[13] pROC_1.18.0          Matrix_1.5-3         viridis_0.6.2       
[16] viridisLite_0.4.1    mmpf_0.0.5           gridExtra_2.3       
[19] mokken_3.0.6         poLCA_1.6.0.1        scatterplot3d_0.3-42
[22] statar_0.7.4         RColorBrewer_1.1-3   car_3.1-1           
[25] carData_3.0-5        dplyr_1.0.10         gbm_2.1.8.1         
[28] smacof_2.1-5         e1071_1.7-12         colorspace_2.0-3    
[31] plotrix_3.8-2        cluster_2.1.4        reshape2_1.4.4      
[34] Hmisc_4.7-2          Formula_1.2-4        survival_3.4-0      
[37] lattice_0.20-45      psych_2.2.9          ggrepel_0.9.2       
[40] ggplot2_3.4.0        huxtable_5.5.2       jtools_2.2.1        
[43] MCMCpack_1.6-3       coda_0.19-4          pscl_1.5.5          
[46] MASS_7.3-58.1        haven_2.5.1         

loaded via a namespace (and not attached):
  [1] backports_1.4.1     systemfonts_1.0.4   plyr_1.8.8         
  [4] lazyeval_0.2.2      splines_4.2.2       listenv_0.9.0      
  [7] SnowballC_0.7.0     candisc_0.8-6       digest_0.6.31      
 [10] htmltools_0.5.4     gdata_2.18.0.1      fansi_1.0.3        
 [13] magrittr_2.0.3      checkmate_2.1.0     tzdb_0.3.0         
 [16] globals_0.16.2      readr_2.1.3         wordcloud_2.6      
 [19] jpeg_0.1-10         textshaping_0.3.6   xfun_0.36          
 [22] hexbin_1.28.2       crayon_1.5.2        jsonlite_1.8.4     
 [25] lme4_1.1-31         glue_1.6.2          gtable_0.3.1       
 [28] nnls_1.4            MatrixModels_0.5-1  weights_1.0.4      
 [31] abind_1.4-5         SparseM_1.81        scales_1.2.1       
 [34] DBI_1.1.3           rstatix_0.7.1       Rcpp_1.0.9         
 [37] xtable_1.8-4        htmlTable_2.4.1     foreign_0.8-83     
 [40] proxy_0.4-27        stats4_4.2.2        heplots_1.4-2      
 [43] htmlwidgets_1.6.1   httr_1.4.4          ellipsis_0.3.2     
 [46] modeltools_0.2-23   mice_3.15.0         farver_2.1.1       
 [49] pkgconfig_2.0.3     nnet_7.3-18         deldir_1.0-6       
 [52] utf8_1.2.2          labeling_0.4.2      tidyselect_1.2.0   
 [55] rlang_1.0.6         polynom_1.4-1       munsell_0.5.0      
 [58] tools_4.2.2         cli_3.5.0           generics_0.1.3     
 [61] broom_1.0.2         stringr_1.5.0       fastmap_1.1.0      
 [64] ragg_1.2.4          mcmc_0.9-7          knitr_1.41         
 [67] pander_0.6.5        rgl_0.110.2         purrr_1.0.0        
 [70] future_1.30.0       nlme_3.1-160        quantreg_5.94      
 [73] tokenizers_0.3.0    compiler_4.2.2      bayesplot_1.10.0   
 [76] rstudioapi_0.14     plotly_4.10.1       png_0.1-8          
 [79] ggsignif_0.6.4      tibble_3.1.8        stringi_1.7.8      
 [82] forcats_0.5.2       nloptr_2.0.3        vctrs_0.5.1        
 [85] furrr_0.3.1         pillar_1.8.1        lifecycle_1.0.3    
 [88] cowplot_1.1.1       data.table_1.14.6   R6_2.5.1           
 [91] latticeExtra_0.6-30 parallelly_1.33.0   janeaustenr_1.0.0  
 [94] codetools_0.2-18    boot_1.3-28         gtools_3.9.4       
 [97] assertthat_0.2.1    withr_2.5.0         mnormt_2.1.1       
[100] broom.mixed_0.2.9.4 mgcv_1.8-41         hms_1.1.2          
[103] grid_4.2.2          rpart_4.1.19        tidyr_1.2.1        
[106] class_7.3-20        minqa_1.2.5         base64enc_0.1-3    
[109] ellipse_0.4.3       interp_1.1-3       

  